package com.gopay.common.cps.dao.aggregatepayment.impl;

import com.gopay.common.base.dao.impl.BaseReadDAOImpl;
import com.gopay.common.cps.dao.aggregatepayment.ApShopInfoQueryDAO;
import com.gopay.common.domain.aggregatepayment.ApShopInfo;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Chenyu Li
 * @description 聚合支付门店查询DAO
 * @date 2018/1/2
 * Copyright (c) 2017. www.gopay.com.cn Inc.All rights reserved.
 */
@Repository("apShopInfoQueryDAO")
public class ApShopInfoQueryDAOImpl extends BaseReadDAOImpl<ApShopInfo,String> implements ApShopInfoQueryDAO {

    /**
     * 根据custId查询信息
     * @author Chenyu Li
     * @date 2018/1/11
     * @params [apShopInfo, pageNo, pageSize]
     * @return java.util.List<com.gopay.common.domain.aggregatepayment.ApShopInfo>
     * @throws
     */
    @Override
    public List<ApShopInfo> getInfoByCustId(ApShopInfo apShopInfo, int pageNo , int pageSize){

        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ApShopInfo.class);
        if(StringUtils.isNotBlank(apShopInfo.getCustId())){
            detachedCriteria.add(Restrictions.eq("custId", apShopInfo.getCustId()));
        }
        if(StringUtils.isNotBlank(apShopInfo.getShopNo())) {
            detachedCriteria.add(Restrictions.like("shopNo", "%" + apShopInfo.getShopNo() + "%"));
        }
        if(StringUtils.isNotBlank(apShopInfo.getShopFullName())) {
            detachedCriteria.add(Restrictions.like("shopFullName", "%" + apShopInfo.getShopFullName() + "%"));
        }
        if(StringUtils.isNotBlank(apShopInfo.getStatus())) {
            detachedCriteria.add(Restrictions.eq("status", apShopInfo.getStatus()));
        }
        return findByCriteria(detachedCriteria,pageNo,pageSize);
    }

    /**
     * 根据custId查询信息技术
     * @author Chenyu Li
     * @date 2018/1/11
     * @params [apShopInfo]
     * @return int
     * @throws
     */
    @Override
    public int getInfoCountByCustId(ApShopInfo apShopInfo){

        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(ApShopInfo.class);
        if(StringUtils.isNotBlank(apShopInfo.getCustId())){
            detachedCriteria.add(Restrictions.eq("custId", apShopInfo.getCustId()));
        }
        if(StringUtils.isNotBlank(apShopInfo.getShopNo())) {
            detachedCriteria.add(Restrictions.like("shopNo", "%" + apShopInfo.getShopNo() + "%"));
        }
        if(StringUtils.isNotBlank(apShopInfo.getShopFullName())) {
            detachedCriteria.add(Restrictions.like("shopFullName", "%" + apShopInfo.getShopFullName() + "%"));
        }
        if(StringUtils.isNotBlank(apShopInfo.getStatus())) {
            detachedCriteria.add(Restrictions.eq("status", apShopInfo.getStatus()));
        }
        return findCountByCriteria(detachedCriteria);
    }
}
